package com.yuxi.Service.Impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yuxi.Dao.InformationFlowDao;
import com.yuxi.Entity.InformationFlow;
import com.yuxi.Service.InformationFlowService;
@Service
public class InformationFlowServiceImpl implements InformationFlowService {
	@Autowired
	private InformationFlowDao informationFlowDao;
	

	@Override
	public void createInformationFlow(int flowId,int informationId,int userId ) {	
		InformationFlow lastFlowNode=informationFlowDao.getInformationFLowByInformationId(informationId);
		int lastFlowNodeId=0;
		if(lastFlowNode!=null){
			lastFlowNodeId=lastFlowNode.getId();
			lastFlowNode.setEndTime(System.currentTimeMillis());
			lastFlowNode.setEnable(false);
			lastFlowNode.setHandle(true);
			informationFlowDao.modiflyFlow(lastFlowNode); 
		}
		
		InformationFlow flow=new InformationFlow(System.currentTimeMillis(), 0, false, flowId, true, informationId,lastFlowNodeId,userId);
		informationFlowDao.addFlow(flow);
	}

	@Override
	public void createInformationFlow(int flowId,int informationId,int userId,String remark,String userName) {	
		InformationFlow lastFlowNode=informationFlowDao.getInformationFLowByInformationId(informationId);
		int lastFlowNodeId=0;
		if(lastFlowNode!=null){
			lastFlowNodeId=lastFlowNode.getId();
			lastFlowNode.setEndTime(System.currentTimeMillis());
			lastFlowNode.setEnable(false);
			lastFlowNode.setHandle(true);
			informationFlowDao.modiflyFlow(lastFlowNode); 
		}		
		InformationFlow flow=new InformationFlow(System.currentTimeMillis(), 0, false, flowId, true, informationId,lastFlowNodeId,userId,remark,userName);
		informationFlowDao.addFlow(flow);
	}
	@Override
	public void createInformationFlow(int flowId,int informationId,int userId,String remark,String userName,String operation) {	
		InformationFlow lastFlowNode=informationFlowDao.getInformationFLowByInformationId(informationId);
		int lastFlowNodeId=0;
		int lastlastFlowId=0;
		if(lastFlowNode!=null){
			lastFlowNodeId=lastFlowNode.getId();
			lastlastFlowId=lastFlowNode.getFlowId();
			lastFlowNode.setEndTime(System.currentTimeMillis());
			lastFlowNode.setEnable(false);
			lastFlowNode.setHandle(true);
			informationFlowDao.modiflyFlow(lastFlowNode); 
		}	
		InformationFlow flow=new InformationFlow(System.currentTimeMillis(), 0, false, flowId, true, informationId,lastFlowNodeId,userId,userName,remark,operation,lastlastFlowId);
		informationFlowDao.addFlow(flow);
	}
	@Override
	public void endInformationFlow(int informationId) {
	InformationFlow in=informationFlowDao.getInformationFLowByInformationId(informationId);	
		
	}

	@Override
	public List<InformationFlow> getInformationFlowByInfoId(int informationId) {
		try {
			List<InformationFlow> iFlows = informationFlowDao.getInformationFLowByInforId(informationId);
			return iFlows;
		} catch (Exception e) {
			return null;
		}
	}

	@Override
	public void createInformationFlow(int flowId, int informationId, int userId, String remark, String userName,
			String operation, Integer pId, String pName) {
		InformationFlow lastFlowNode=informationFlowDao.getInformationFLowByInformationId(informationId);
		int lastFlowNodeId=0;
		int lastlastFlowId=0;
		if(lastFlowNode!=null){
			lastFlowNodeId=lastFlowNode.getId();
			lastlastFlowId=lastFlowNode.getFlowId();
			lastFlowNode.setEndTime(System.currentTimeMillis());
			lastFlowNode.setEnable(false);
			lastFlowNode.setHandle(true);
			informationFlowDao.modiflyFlow(lastFlowNode); 
		}	
		InformationFlow flow=new InformationFlow(System.currentTimeMillis(), 0, false, flowId, true, informationId,lastFlowNodeId,userId,userName,remark,operation,lastlastFlowId);
		flow.setPrisonId(pId);
		flow.setPrisonName(pName);
		informationFlowDao.addFlow(flow);
		
	}

	@Override
	public InformationFlow getPrisonFlowByInfoId(int informationId) {
		// TODO Auto-generated method stub
		return null;
	}

}
